
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "led.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


void Led_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;


	/* GPIOE Periph clock enable */
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);

	/* Configure PE[12:11] in output pushpull mode */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOE, &GPIO_InitStructure);
}

void Led_Set(u32 led, u32 on)
{
	switch (led) {
	case LED_RED:
		GPIO_WriteBit(GPIOE, GPIO_Pin_11, on ? Bit_SET : Bit_RESET);
		break;
	case LED_GREEN:
		GPIO_WriteBit(GPIOE, GPIO_Pin_12, on ? Bit_SET : Bit_RESET);
		break;
	}
}

u32 Led_Get(u32 led)
{
	switch (led) {
	case LED_RED:
		return GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_11);
	case LED_GREEN:
		return GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_12);
	}

	return (u32)-1;
}

void Led_Toggle(u32 led)
{
	Led_Set(led, !Led_Get(led));
}


